<?php
/**
 * Created by PhpStorm.
 * User: zouhua
 * Date: 2018/1/5
 * Time: 14:57
 */

namespace app\controllers;


use app\components\AppController;
use app\helpers\AppHelper;
use app\models\Categories;
use app\models\Post;
use app\models\Setting;
use yii\web\NotFoundHttpException;

class PostController extends AppController {

    public function actionIndex() {
        return $this->render();
    }

    public function actionDetail() {
        $id = $this->get('id');
        $where = is_numeric($id) ? ['id' => $id] : ['slug' => $id];

        $model = Post::findOne($where);
        if (!$model) {
            throw new NotFoundHttpException("post id: {$id} not found.");
        }

        $this->view->title = "{$model->slug} {$model->title}";
        $this->keywords = "{$model->slug},{$model->slug} BT,{$model->slug}下载,{$model->slug}迅雷";
        $this->description = $this->view->title;

        $view = '/' . Categories::$typeViews[$model->type] . '/detail';
        return $this->render(compact('model'), $view);
    }

}